﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;

using Gift.Model.ENUM;

namespace WebSite.admin.product
{
    public partial class brand_add : BaseAdmin
    {
     

        // Methods
        protected void Button1_Click(object sender, EventArgs e)
        {
            upload upload = new upload();
            string str = upload.Up(this.file1, "../../uploadfile/product/");
            base.Response.Write(upload.Resup[Convert.ToInt32(str)]);
            this.pinpailogo.Text = upload.s;
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (base.Request.QueryString["pid"] != null)
            {
                SQLAccess.DoSql(string.Concat(new object[] { 
                "update DB_Pinpai set pinpainame='", re.replace(this.pinpainame.Value), "',pinpaiorder=", re.replace(this.pinpaiorder.Value), ",visible=", this.CheckBox1.Checked  ? "1" : "0", ",isnew=",  this.CheckBox2.Checked  ? "1" : "0" , ",pinpaicontent='", re.replace(this.pinpaicontent.Text), "',pinpailogo='", re.replace(this.pinpailogo.Text), "',pinpaiurl='", re.replace(this.pinpaiurl.Value), "' where pinpaiid=", base.Request.QueryString["pid"], 
                ""
             }));
                base.Response.Write("<script language='javascript'>alert('商品品牌修改成功');window.location.href='brand.aspx';</script>");
                base.Response.End();
            }
            else
            {
                SQLAccess.DoSql(string.Concat(new object[] { 
                "insert into DB_Pinpai (pinpainame,pinpaiurl,pinpailogo,pinpaicontent,pinpaiorder,visible,isnew,languages) values ('", re.replace(this.pinpainame.Value), "','", re.replace(this.pinpaiurl.Value), "','", re.replace(this.pinpailogo.Text), "','", re.replace(this.pinpaicontent.Text), "',", re.replace(this.pinpaiorder.Value), ",",  this.CheckBox1.Checked ? "1" : "0" , ",",  this.CheckBox2.Checked  ? "1" : "0", ",", info.languages(""), 
                ")"
             }));
                base.Response.Write("<script language='javascript'>alert('商品品牌添加成功');window.location.href='brand.aspx';</script>");
                base.Response.End();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                base.ValidateLoginRule(ERule.AddProductBrand);
            }
            this.ImageButton1.Attributes["onclick"] = "return CheckFrm()";
            if (!base.IsPostBack && (base.Request.QueryString["pid"] != null))
            {
                this.upbind();
            }
        }

        private void upbind()
        {
            string sql = "select top 1 * from DB_Pinpai where pinpaiid=" + base.Request.QueryString["pid"];
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            this.pinpainame.Value = table.Rows[0]["pinpainame"].ToString();
            this.pinpaiurl.Value = table.Rows[0]["pinpaiurl"].ToString();
            this.pinpailogo.Text = table.Rows[0]["pinpailogo"].ToString();
            this.pinpaicontent.Text = table.Rows[0]["pinpaicontent"].ToString().Replace("<br/>", "\n");
            this.CheckBox1.Checked = (bool)table.Rows[0]["visible"];
            this.CheckBox2.Checked = (bool)table.Rows[0]["isnew"];
        }


    }
}